package fun.tan90.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;


/**
 * 消费者
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = "ironman_stadium_topic",
        consumerGroup = "rocketmq_study_2_group",
        // 消费模式 负载均衡
        messageModel = MessageModel.CLUSTERING,
        // 过滤方式基于TAG
        selectorType = SelectorType.TAG,
        selectorExpression = "uface-person-res",
        // 并行消费
        consumeMode = ConsumeMode.CONCURRENTLY,
        // 设置重试次数
        maxReconsumeTimes = 3)
public class RocketMqStudy1Consumer implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        log.info("msgId:{} 业务KEY:{} 重试次数:{} 消息体:{}",
                messageExt.getMsgId(),
                messageExt.getKeys(),
                messageExt.getReconsumeTimes(),
                new String(messageExt.getBody()));
    }

}
